home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / answrbok / 4_10.lha / 4_10 / 4_10b0.c < prev    next >
Text File  |  1993-08-08  |  809b  |  33 lines

  1. * Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */
  2. * The C++ Answer Book */
  3. * Tony Hansen */
  4. * All rights reserved. */
  5. / Exercise 4.10 (version 1)
  6. / Invert a two dimensional (n X n) array
  7. / using the Gauss-Jordan elimination method.
  8. / Return 1 if succeeded, 0 if singular.
  9. include <swap.h>
  10.  
  11. / Find A[i][d] which is non zero, i >= d,
  12. / and swap with A[d][d].
  13. / Return FALSE if there are no non-zero entries.
  14. tatic int dopivot(double **A, double **I,
  15.    int diag, int nelem)
  16.  
  17.    if (A[diag][diag] != 0.0)
  18.        return 1;
  19.  
  20.    for (int i = diag+1; i < nelem; i++)
  21. if (A[i][diag] != 0.0)
  22.     {
  23.     // swap row i with row diag in A and I
  24.     swap(A[diag], A[i]);
  25.     swap(I[diag], I[i]);
  26.     break;
  27.     }
  28.  
  29.    // if no non-zero entries (i == nelem),
  30.    // then failure
  31.    return i < nelem;
  32.  
  33.